﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace Easy.AspNetMvc
{
    public static class ControllerExtention
    {
        public static ContentResult ReturnSuccessMessage(this Controller controller, string message = null, object data = null)
        {
            var result = new { IsSuccess = true, Message = message ?? Resource.SuccessMessage, Data = data };

            return new ContentResult
            {
                Content = JsonConvert.SerializeObject(result, Formatting.Indented),
                ContentEncoding = Encoding.UTF8,
                ContentType = "text/json"
            };
        }

        public static ContentResult ReturnFailureMessage(this Controller controller, string message = null, object data = null)
        {
            var result = new { IsSuccess = false, Message = message ?? Resource.FailureMessage, Data = data };

            return new ContentResult
            {
                Content = JsonConvert.SerializeObject(result, Formatting.Indented),
                ContentEncoding = Encoding.UTF8,
                ContentType = "text/json"
            };
        }
    }
}
